<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    // 如果是直接访问JSP，重定向到Servlet
    if(request.getAttribute("carouselNews") == null) {
        response.sendRedirect(request.getContextPath() + "/user/home");
        return;
    }
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>
    <title>教育新闻网</title>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.css" rel="stylesheet">
    <style>
        body {
            position: relative;
            min-height: 100vh;
            margin: 0;
            padding: 0;
        }
        .background-container {
            position: fixed;
            width: 400px;
            height: 400px;
            left: 50%;
            transform: translateX(-50%);
            background-image: url('${pageContext.request.contextPath}/static/images/sy_main_bg.png');
            background-repeat: no-repeat;
            background-size: contain;
            background-position: center;
            z-index: 99;
            opacity: 0.5;
            pointer-events: none;
            display: none; /* 初始状态隐藏 */
        }
        .content-wrapper {
            position: relative;
            z-index: 1;
            background-color: rgba(255, 255, 255, 0.9);
        }
        .swiper {
            width: 100%;
            height: 500px;
            background-color: #fff;
            position: relative;
            z-index: 2;
        }
        .swiper-slide {
            position: relative;
        }
        .swiper-slide img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .swiper-slide .title {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            padding: 20px;
            background: rgba(0, 0, 0, 0.5);
            color: white;
        }
        /* 校园风采样式 */
        .campus-style-list {
            margin-bottom: 2rem;
            position: relative;
        }
        .campus-style-item {
            display: flex;
            padding: 1.5rem;
            border: 1px solid #eee;
            border-radius: 8px;
            margin-bottom: 1rem;
            transition: all 0.3s ease;
            background-color: rgba(255, 255, 255, 0.9);
        }
        .campus-style-item:hover {
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            transform: translateY(-2px);
        }
        .campus-style-image {
            width: 200px;
            height: 150px;
            object-fit: cover;
            border-radius: 4px;
            margin-right: 1.5rem;
        }
        .campus-style-content {
            flex: 1;
            overflow: hidden;
        }
        .campus-style-title {
            font-size: 1.25rem;
            font-weight: 600;
            margin-bottom: 0.75rem;
            color: #333;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        .campus-style-description {
            color: #666;
            line-height: 1.6;
            margin-bottom: 0;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div class="background-container"></div>
    <div class="content-wrapper">
        <!-- 引入头部 -->
        <jsp:include page="/user/common/header.jsp"/>
        
        <!-- 轮播图 -->
        <div class="swiper mb-5">
            <div class="swiper-wrapper">
                <c:forEach items="${carouselNews}" var="news">
                    <div class="swiper-slide">
                        <a href="${pageContext.request.contextPath}/user/news/detail?id=${news.newsId}">
                            <img src="${pageContext.request.contextPath}/${news.imageUrl}" alt="${news.title}">
                            <div class="title">
                                <h3>${news.title}</h3>
                            </div>
                        </a>
                    </div>
                </c:forEach>
            </div>
            <div class="swiper-pagination"></div>
        </div>
        
        <!-- 校园风采 -->
        <div class="container">
            <h2 class="mb-4">校园风采</h2>
            <div class="campus-style-list">
                <c:forEach items="${campusStyles}" var="style">
                    <a href="${pageContext.request.contextPath}/user/campus-style/detail?id=${style.styleId}" 
                       class="text-decoration-none">
                        <div class="campus-style-item">
                            <img src="${pageContext.request.contextPath}/${style.imageUrl}" 
                                 class="campus-style-image" alt="${style.title}">
                            <div class="campus-style-content">
                                <h3 class="campus-style-title">${style.title}</h3>
                                <p class="campus-style-description">${style.description}</p>
                            </div>
                        </div>
                    </a>
                </c:forEach>
            </div>
        </div>
        
        <!-- 引入底部 -->
        <jsp:include page="/user/common/footer.jsp"/>
    </div><!-- 结束 content-wrapper -->
    
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.js"></script>
    <script>
        new Swiper('.swiper', {
            loop: true,
            autoplay: {
                delay: 3000,
                disableOnInteraction: false,
            },
            pagination: {
                el: '.swiper-pagination',
                clickable: true,
            }
        });

        document.addEventListener('DOMContentLoaded', function() {
            const backgroundContainer = document.querySelector('.background-container');
            const swiper = document.querySelector('.swiper');
            
            if (backgroundContainer && swiper) {
                // 获取轮播图底部的位置
                const swiperBottom = swiper.offsetTop + swiper.offsetHeight;
                
                // 设置初始状态
                checkScroll();
                
                // 监听滚动事件
                window.addEventListener('scroll', checkScroll);
                
                function checkScroll() {
                    const scrollPosition = window.scrollY;
                    
                    // 只有当滚动超过轮播图底部时才显示背景
                    if (scrollPosition > swiperBottom - window.innerHeight) {
                        backgroundContainer.style.display = 'block';
                        backgroundContainer.style.top = Math.max(swiperBottom, scrollPosition) + 'px';
                    } else {
                        backgroundContainer.style.display = 'none';
                    }
                }
            }
        });
    </script>
</body>
</html> 